package controllers

import dao._
import play.api.libs.json.Json
import play.api.mvc.{AbstractController, ControllerComponents}

import javax.inject.Inject
import scala.collection.immutable.SeqMap
import implicits.Implicits._

import java.io.File
import scala.concurrent.ExecutionContext.Implicits.global

/**
 * Created by yz on 13/8/2021
 */
class TestController @Inject()(cc: ControllerComponents)(
  implicit val bioSampleDao: BioSampleDao,
) extends AbstractController(cc) {

  val parentDir = new File("E:\\mtd_database\\test")

  def produceGroup = Action.async { implicit request =>
    bioSampleDao.selectAllIdLocation.map { idLocations =>
      val trueLocationMap = SeqMap("USA" -> "United States of America")
      val trueIdLocations = idLocations.map { case (id, location) =>
        (id, location.mySplit(":").head)
      }
      val lines = trueIdLocations.map { case (id, location) =>
        val trueLocation = trueLocationMap.getOrElse(location, location)
        List(id, trueLocation)
      }.toList
      lines.toFile(new File(parentDir, "group.csv"))
      Ok("success!")
    }

  }


}
